package com.glp.work.flow.config.interceptor;

import java.util.UUID;

import org.slf4j.MDC;
import org.springframework.context.annotation.Configuration;

import com.glp.work.flow.constant.Keys;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

/** 
*
* @author  pengjia 
* @version 2020年8月24日 上午11:28:50 
*/
@Configuration
@Slf4j
public class TracePreFilter  implements RequestInterceptor{
	
	@Override
	public void apply(RequestTemplate template) {
		String traceId = MDC.get(Keys.LOG_TRACE_ID);
		if(traceId == null) {
			traceId = UUID.randomUUID().toString();
		}
		log.debug("生成日志的traceId：", traceId);
		template.header(Keys.LOG_TRACE_ID, traceId);
	}

}
